package cn.bdqn.service.questionBank;


import cn.bdqn.dao.questionBank.OperationRecordDao;
import cn.bdqn.dto.questionBank.subject.SubjectAccountTypeDTO;
import cn.bdqn.pojo.questionBank.OperationRecord;
import cn.bdqn.utils.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service("operationRecordService")
public class OperationRecordService {

    @Autowired
    private OperationRecordDao operationRecordDao;

    /**
     * 查询所有操作
     * @return
     */
    public Json selectAllOperationRecord(){
        OperationRecord operationRecord = new OperationRecord();
        operationRecord.setOperationRecordRemarks("sdfsdfsf");
        int a = operationRecordDao.insert(operationRecord);
        System.out.println(a);
        System.out.println(operationRecord.getOperationRecordId());
        return null;
    }

    /**
     * 添加操作信息
     * @param operationRecord
     * @return
     */
    public OperationRecord insertOperationRecord(OperationRecord operationRecord){
        int a = operationRecordDao.insert(operationRecord);
        if(a == 1){
            //System.out.println("添加成功");
            return operationRecord;
        }
        return null;
    }

    /**
     * 操作记录添加方法
     * @param userId
     * @param message
     * @param subjectAccountTypeDTO
     * @return
     */
    public OperationRecord operationRecordPublicMethod(Integer userId, String message, SubjectAccountTypeDTO subjectAccountTypeDTO){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        OperationRecord operationRecord = new OperationRecord();
        operationRecord.setOperationRecordRemarks(subjectAccountTypeDTO.getOperationRecordRemarks() == null ? message : subjectAccountTypeDTO.getOperationRecordRemarks());
        operationRecord.setOperationRecordDescribe(message);
        operationRecord.setOperationRecordTime(subjectAccountTypeDTO.getTime() == null ? simpleDateFormat.format(new Date()) : subjectAccountTypeDTO.getTime());
        operationRecord.setUserId(userId);
        if(insertOperationRecord(operationRecord) == null){
            return null;
        }
        return operationRecord;
    }
}
